package com.zyn.rsgl.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zyn.rsgl.pojo.Salary;
import com.zyn.rsgl.mapper.SalaryMapper;
import com.zyn.rsgl.service.SalaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyn.rsgl.utils.commonResult.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 薪资表 服务实现类
 * </p>
 *
 * @author zyn
 * @since 2024-04-10
 */
@Service
public class SalaryServiceImpl extends ServiceImpl<SalaryMapper, Salary> implements SalaryService {

    @Resource
    SalaryMapper salaryMapper;
    @Override
    public R listPage(Integer pageNum, Integer pageSize, String userId, String positionName) {
        // 构造查询器
        QueryWrapper<Salary> salaryQueryWrapper = new QueryWrapper<>();
        if (userId != null) {
            salaryQueryWrapper.like("user_id", userId);
        }
        if (positionName != null) {
            salaryQueryWrapper.like("position_name", positionName);
        }
        // 初始化分页查询
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);
        List<Salary> list = this.list(salaryQueryWrapper);
        if (list != null) {
            return R.ok(list, page.getTotal());
        }
        return R.fail("查询失败");
    }

    @Override
    public Salary getByUserId(String userId) {
        return salaryMapper.getByUserId(userId);
    }
}
